/*绑定回车到查询按钮*/
$(function(){
	$(document).keydown(function(){ 
		if(event.keyCode==13){ 
		$("#chaxun").trigger('click'); 
		return false;
		}
	});
});
var huanzheid='';
//门诊记录点击查询
$("#chaxun").click(function(){
    xingmingsj = $('#mingcheng').val();
    kaishisj = $('#mzjl-kaishjsj').val();
    jieshusj = $('#mzjl-jieshusj').val();
    getMenzhenjl();
})
//传递初始时间
function getShijian(prekaishisj,prejieshusj){
		//清空查询条件
		$("#qingkongtj").click(function(){
		$('#mingcheng').val('');
	    $('#mzjl-kaishjsj').val(prekaishisj);
	    $('#mzjl-jieshusj').val(prejieshusj);
//	    查询条件重置后进行查询
	   if(prekaishisj!=null){
			kaishisj=prekaishisj;
	    	jieshusj=prejieshusj;
	    	xingmingsj='';
	    	getMenzhenjl();
		}
	});
//		页面加载是进行查询
		if(prekaishisj!=null){
			kaishisj=prekaishisj;
	    	jieshusj=prejieshusj;
	    	xingmingsj='';
	    	getMenzhenjl();
		}
}


var kaishisj = '';
var jieshusj ='';
var xingmingsj = '';

//门诊记录列表查询
function getMenzhenjl(){
		var totalNumber = 0;
		var params={
			kaishisj:kaishisj,
			jieshusj:jieshusj,
			xingmingsj:xingmingsj
		};
		$.ajax({
		    type:"POST",
		    url:"../chaxuntjmzjl/getMenzhentj",
		    data:params,
		    async:false,
		    success: function(data){
				if(data != null) {
					totalNumber = data.jiuzhenrc;
					$('#mzjiuzhenrc').text(data.jiuzhenrc);
					$('#mzyingshouje').text('￥'+data.yingshouje.toFixed(2));
					$('#mzshishouje').text('￥'+data.shishouje.toFixed(2));
					$('#mzyibaobxje').text('￥'+data.yibaobxje.toFixed(2));
					if(totalNumber == 0){
						$("#chaxtjmzjl-biaotou").css("display","none");
						$("#chaxtjmzjl-tbneirong").css("display","none");
						$("#mz-img").html("<img src='"+path+"/image/chaxtj/cxtj-nobody.png'>");
					}else{
						$("#chaxtjmzjl-biaotou").css("display","block");
						$("#chaxtjmzjl-tbneirong").css("display","block");
						$("#mz-img").html("");
					}
				}
			}
		});
		function createDemo(name) {
			$('#tbmenzhenjl').html('');
		  var container = $('#pagination-'+name);
		  container.pagination({
		    dataSource:'../chaxuntjmzjl/getByPage?kaishisj='+encodeURI(kaishisj)+'&jieshusj='+encodeURI(jieshusj)+'&xingmingsj='+encodeURI(xingmingsj),
		    locator: 'entities',
		    pageSize: 12,
		    totalNumber: totalNumber,
			showNavigator: true,
	   	    formatNavigator: '共 <%= totalNumber %> 条',
		    callback: function(data, pagination) {
		    	if(data!=null) {
					var contentmz = '';
					$(data).each(function(index,e){
						var nianling = this.nianling;
	    				var nianlingdw = this.nianlingdw;
	    				nianling = nianling + nianlingdw;
	    				if(this.nianling==null) {
	    					nianling = '';
	    				}
						var xingbie = this.xingbie;
						if(xingbie==1) {
							xingbie = '男';
						}else if(xingbie==2) {
							xingbie = '女';
						}else{
							xingbie = '';
						}
						var shoujihm = this.shoujihm || '';
						index = ((pagination.pageNumber-1)*pagination.pageSize)+index+1;
						contentmz += '<tr class="user">'+
						'<td width="6%">'+index+'</td>'+
						'<td width="10%" class="left"><span class="icon-user" onclick=getHuanzhe('+this.huanzheid+')></span>'+this.xingming+'</td>'+
						'<td width="6%">'+xingbie+'</td>'+
						'<td width="6%">'+nianling+'</td>'+
						'<td width="12%">'+shoujihm+'</td>'+
						'<td class="left" width="13%">'+this.jibingmc+'</td>'+
						'<td width="10%">'+this.yishengmc+'</td>'+
						'<td width="8%" class="right">'+this.shishouje.toFixed(2)+'</td>'+
						'<td width="12%" class="right">'+this.yibaobxje.toFixed(2)+'</td>'+
						'<td width="8%" class="right">'+this.zongjine.toFixed(2)	+'</td>'+
						'<td width="9%">'+this.jiuzhensj+'</td>'+
						'</tr>';
					});
					$('#tbmenzhenjl').html(contentmz);
				}
		    }
		  });
		  return container;
		}
		createDemo('fenymzjl');
		if(totalNumber <= 12) {
			$('#pagination-fenymzjl').css('display','none');
		}else{
			$('#pagination-fenymzjl').css('display','block');
		}
}
